﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using V = Science.Mathematics.VectorCalculus;

namespace VectorCalculus5Ed.Chapter6.Section2
{
    public class Example03
    {
        public Example03()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
        public void Compute()
        {
            V.Function.ToLastType<double[], double> f
                = new V.Function.ToLastType<double[], double>(func);
            double[] from = { 0.0, -2.0 };
            double[] to = { 1.0, 0.0 };
            V.IntegrationMultiD obj = new V.IntegrationMultiD(f, from, to);
            obj.Compute();
            result += obj.BestEstimation.ToString() + "\r\n";
        }
        private double func(double[] u)
        {
            return Math.Abs(jac(u))*funcxy(funcT(u));
        }
        private double[] funcT(double[] u)
        {
            double[] x = new double[2];
            x[0] = u[0] - u[1];
            x[1] = 2.0*u[0] - u[1];
            return x;
        }
        private double jac(double[] u)
        {
            double[] at = { u[0], u[1] };
            V.Function.ToLastType<double[], double[]> f
                = new V.Function.ToLastType<double[], double[]>(funcT);
            V.JacobianDeterminant obj = new V.JacobianDeterminant(f, at);
            obj.Compute();
            return obj.Result;
        }
        private double funcxy(double[] x)
        {
            return x[0]*x[1];
        }
    }
}
/* 
7.00003248042549
*/
